import { createRouter,createWebHashHistory} from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {path:"/",redirect:"/profile"},
    {path:"/profile",component:()=>import("@/views/ProfileEdit.vue"),meta:{title:"个人资料"}},
    {path:"/address",component:()=>import("@/views/AddressManager.vue"),meta:{title:"地址列表"}},
    {path:"/address/edit/:id?",component:()=>import("@/views/AddressEdit.vue"),meta:{title:"地址管理"}},
  ]
})


// 访问任何的页面组件, 都会经过两个钩子函数(路由的前置守卫, 路由的后置守卫)
// 路由的前置守卫
router.beforeEach((to) => {
  console.log(to);
  // 修改网页的标题
  document.title = to.meta.title as string || '美寇'
})

// 路由的后置守卫
// router.afterEach((to) => {
//   console.log(to);
// })

export default router
